/**
 * 
 */
package com.googlecode.dynargs.extractor;

import com.googlecode.dynargs.model.type.ArrayType;
import com.googlecode.dynargs.model.type.Type;

/**
 * @author Federico De Faveri defaveri@gmail.com
 *
 */
public class ArrayExtractor implements TypeExtractor<ArrayType> {

	/**
	 * {@inheritDoc}
	 */
	@Override
	public boolean canExtract(TypeToken typeToken) {
		Class<?> clazz = typeToken.getRawType();
		return clazz.isArray();
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public ArrayType extract(ModelExtractor modelExtractor, TypeToken typeToken) {
		Class<?> clazz = typeToken.getRawType();
		Class<?> componentType = clazz.getComponentType();
		Type arrayType = modelExtractor.extract(componentType);
		String id = clazz.getName();
		return new ArrayType(id, arrayType);
	}

}
